// 
// Copyright (c) 2006-2009 Ben Motmans
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// Author(s):
//    Ben Motmans <ben.motmans@gmail.com>
//

using System;
using System.Reflection;

namespace Anculus.Core
{
	/// <summary>
	/// Assembly attribute used to specify the config file used to configure the <see cref="Log"/> utility.
	/// </summary>
	[AttributeUsage (AttributeTargets.Assembly)]
	public class LogConfigurationAttribute : Attribute
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="LogConfigurationAttribute"/> class.
		/// </summary>
		/// <param name="fileName">
		/// Name of the file.
		/// 
		/// The filename supports several dynamic values:
		/// %config_directory	replaced with Config.Directory
		/// %app_name		replaced with Config.ApplicationName
		/// %company_name	replaced with Config.CompanyName
		/// </param>
		public LogConfigurationAttribute (string fileName)
		{
			if (fileName == null)
				throw new ArgumentNullException ("fileName");
			
			FileName = fileName;
			
			FileName = FileName.Replace ("%config_directory", Config.Directory);
			FileName = FileName.Replace ("%app_name", Config.ApplicationName);
			FileName = FileName.Replace ("%company_name", Config.CompanyName);
		}

		/// <summary>
		/// Gets or sets the name of the file.
		/// </summary>
		/// <value>The name of the file.</value>
		public string FileName { get; protected set; }
	}

	/// <summary>
	/// 
	/// </summary>
	[AttributeUsage (AttributeTargets.Assembly)]
	public class LogCategoryAttribute : Attribute
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="LogCategoryAttribute"/> class.
		/// </summary>
		/// <param name="level">The minimal loglevel.</param>
		public LogCategoryAttribute (LogLevel level)
		{
			Assembly ass = Assembly.GetCallingAssembly (); //TODO: is this correct ??
			
			Category = ass.GetName ().Name;
			LogLevel = level;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="LogCategoryAttribute"/> class.
		/// </summary>
		/// <param name="ns">The namespace.</param>
		/// <param name="level">The minimal loglevel.</param>
		public LogCategoryAttribute (string ns, LogLevel level)
		{
			if (ns == null)
				throw new ArgumentNullException ("ns");
			
			Category = ns;
			LogLevel = level;
		}

		/// <summary>
		/// Gets or sets the category.
		/// </summary>
		/// <value>The category.</value>
		public string Category { get; protected set; }

		/// <summary>
		/// Gets or sets the log level.
		/// </summary>
		/// <value>The log level.</value>
		public LogLevel LogLevel { get; protected set; }
	}
}